 function basePath(){
    //获取当前网址，如： http://localhost:8080/ems/Pages/Basic/Person.jsp
    var curWwwPath = window.document.location.href;
    //获取主机地址之后的目录，如： /ems/Pages/Basic/Person.jsp
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8080
    var localhostPath = curWwwPath.substring(0, pos);
    //获取带"/"的项目名，如：/ems
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    //获取项目的basePath   http://localhost:8080/ems/
    var basePath=localhostPath+projectName+"/";
    return basePath;
};

jQuery(document).ready(function() {
	//获取主键
	var pk = window.parent.document.getElementById("ifModal3").contentWindow.location.search.substring(1);
	pk = pk.replace('pk=', '');
	
	init(pk);
	initQuestion(pk);
		
});

function init(pk){
	var da={};
	da.QUESTIONNAIREID = pk;
	da.pageNum="1";
	da.pageSize="1";
	$.ajax({
		type:"post",
		url: basePath() + 'question/list.do',
		data:JSON.stringify(da),
		dataType: "json",
		contentType : 'application/json;charset=UTF-8',
		success: function(data){	
			$("#pk3").val(data.rows[0].QUESTIONNAIREID);
			$("#title3").html(data.rows[0].QUESTIONNAIRETITLE);
			$("#disc3").text(data.rows[0].QUESTIONNAIREDISC);
		}
	});			
}

function initQuestion(pk){
	var da={};
	da.QUESTIONNAIREID=pk;
	da.pageNum="1";
	da.pageSize="999";
	$.ajax({
 		type : "post",
 		url : projectPath + 'question/qlist.do',
 		data : JSON.stringify(da),
 		dataType : "json",
 		async : false,
 		contentType : 'application/json;charset=UTF-8',
 		success : function(data) {
 			var questions = data.rows;
 			var info = "";
 			for (var i = 0; i < questions.length; i++) {
 				var question = questions[i];
 				info += '<div class="form-group"><div class="col-sm-1"></div><div class="col-sm-10"><hr style="height:1px;border:none;border-top:1px solid #555555;" />';
 				info += '<h4>' + question.QUESTIONORDER + '. '+ question.QUESTION + '</h4>';
 				var items = question.QUESTIONITEM;
 				var item = items.split(",");
 				var results = question.ITEMNUM;
 				var result = results.split(",");
 				var zong = 0;
 				for (var z = 0; z < result.length; z++) {
 					zong += parseInt(result[z]);
 				}
 				for (var j = 0; j < item.length; j++) {
 					var fen = parseInt(result[j]);
 					var jl = zong == 0 ? 0 : fen / zong * 100;
 					jl = jl.toFixed(2);
 					info += '<div class="form-group">' +
 					        '	<div class="col-sm-3">' + item[j]+ '</div>' +
 					        '	<div class="col-sm-6">' +
 							'		<div class="progress" style="width: 400px;margin-bottom: 0px;margin-top: 2px;">'+
 							'			<div class="progress-bar bg-success" style="width:'+ jl + '%;">' + jl + '%</div>' +
 					        '		</div>' +
 							'	</div>' +
 					        '	<div class="col-sm-2">' + fen + '票</div>' + 
 					        '</div>';
 				}

 				info += '</div><div class="col-sm-1"></div></div>';
 			}

 			$("#info").html(info);
 		}
 	});
}